﻿package net.wangit.dev.incrementor;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.dev.ConsoleDomainUtil;
import net.wangit.dev.ReferenceUtil;
import net.wangit.jdbc.util.DBHelper;
import net.wangit.support.UnitInterceptor;
import net.wangit.util.Checker;

public class TableReferenceUI implements UnitInterceptor {

	public TableReferenceUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String incrementorId = ac.getRequestParameter("iid");
		String domain = ConsoleDomainUtil.getDomain(ac);
		if (!Checker.isEmpty(domain) && !Checker.isEmpty(incrementorId)) {
			net.wangit.jdbc.DB db = DBHelper.getDomainDB(domain);
			net.wangit.MapList data = ReferenceUtil.getIncrementorReference(
					db, incrementorId);
			unit.setData(data);
		}
		return unit.write(ac);
	}
}
